/******************************************************************************
 * @file    lcd_1289.h
 * @version V1.0
 * @brief   TFT Driver program
 ******************************************************************************/
#ifndef _H_LCD_H_
#define _H_LCD_H_

#include "grammer.h"
#include "stm32f1xx_hal.h"

//屏幕旋转定义 数字按照 ID[1:0]AM 按照PDF中的配置定义

#define ID_AM 110

//硬件相关的子函数

#define Lcd_Light_ON
#define Lcd_Light_OFF

#define SetCs HAL_GPIO_WritePin(LCD_PORT_CS, LCD_Pin_CS, GPIO_PIN_SET);
#define ClrCs HAL_GPIO_WritePin(LCD_PORT_CS, LCD_Pin_CS, GPIO_PIN_RESET);

#define SetWr HAL_GPIO_WritePin(LCD_PORT_WR, LCD_Pin_WR, GPIO_PIN_SET);
#define ClrWr HAL_GPIO_WritePin(LCD_PORT_WR, LCD_Pin_WR, GPIO_PIN_RESET);

#define SetRs HAL_GPIO_WritePin(LCD_PORT_RS, LCD_Pin_RS, GPIO_PIN_SET);
#define ClrRs HAL_GPIO_WritePin(LCD_PORT_RS, LCD_Pin_RS, GPIO_PIN_RESET);

#define SetRd HAL_GPIO_WritePin(LCD_PORT_RD, LCD_Pin_RD, GPIO_PIN_SET);
#define ClrRd HAL_GPIO_WritePin(LCD_PORT_RD, LCD_Pin_RD, GPIO_PIN_RESET);

////////////////////////////////////////////////////////////////////////////////////////
/* LCD Control pins */
#define LCD_Pin_WR GPIO_PIN_14
#define LCD_PORT_WR GPIOB
//#define LCD_CLK_WR      RCC_APB2Periph_GPIOB

#define LCD_Pin_CS GPIO_PIN_8
#define LCD_PORT_CS GPIOC
//#define LCD_CLK_CS      RCC_APB2Periph_GPIOC

#define LCD_Pin_RS GPIO_PIN_13
#define LCD_PORT_RS GPIOD
//#define LCD_CLK_RS      RCC_APB2Periph_GPIOD

#define LCD_Pin_RD GPIO_PIN_15
#define LCD_PORT_RD GPIOD
//#define LCD_CLK_RD      RCC_APB2Periph_GPIOD

/* LCD Registers */
#define R0 0x00
#define R1 0x01
#define R2 0x02
#define R3 0x03
#define R4 0x04
#define R5 0x05
#define R6 0x06
#define R7 0x07
#define R8 0x08
#define R9 0x09
#define R10 0x0A
#define R12 0x0C
#define R13 0x0D
#define R14 0x0E
#define R15 0x0F
#define R16 0x10
#define R17 0x11
#define R18 0x12
#define R19 0x13
#define R20 0x14
#define R21 0x15
#define R22 0x16
#define R23 0x17
#define R24 0x18
#define R25 0x19
#define R26 0x1A
#define R27 0x1B
#define R28 0x1C
#define R29 0x1D
#define R30 0x1E
#define R31 0x1F
#define R32 0x20
#define R33 0x21
#define R34 0x22
#define R36 0x24
#define R37 0x25
#define R40 0x28
#define R41 0x29
#define R43 0x2B
#define R45 0x2D
#define R48 0x30
#define R49 0x31
#define R50 0x32
#define R51 0x33
#define R52 0x34
#define R53 0x35
#define R54 0x36
#define R55 0x37
#define R56 0x38
#define R57 0x39
#define R59 0x3B
#define R60 0x3C
#define R61 0x3D
#define R62 0x3E
#define R63 0x3F
#define R64 0x40
#define R65 0x41
#define R66 0x42
#define R67 0x43
#define R68 0x44
#define R69 0x45
#define R70 0x46
#define R71 0x47
#define R72 0x48
#define R73 0x49
#define R74 0x4A
#define R75 0x4B
#define R76 0x4C
#define R77 0x4D
#define R78 0x4E
#define R79 0x4F
#define R80 0x50
#define R81 0x51
#define R82 0x52
#define R83 0x53
#define R96 0x60
#define R97 0x61
#define R106 0x6A
#define R118 0x76
#define R128 0x80
#define R129 0x81
#define R130 0x82
#define R131 0x83
#define R132 0x84
#define R133 0x85
#define R134 0x86
#define R135 0x87
#define R136 0x88
#define R137 0x89
#define R139 0x8B
#define R140 0x8C
#define R141 0x8D
#define R143 0x8F
#define R144 0x90
#define R145 0x91
#define R146 0x92
#define R147 0x93
#define R148 0x94
#define R149 0x95
#define R150 0x96
#define R151 0x97
#define R152 0x98
#define R153 0x99
#define R154 0x9A
#define R157 0x9D
#define R192 0xC0
#define R193 0xC1
#define R229 0xE5

/* LCD color */
#define White 0xFFFF
#define Black 0x0000
#define Grey 0xF7DE //灰色
#define Blue 0x001F
#define Blue2 0x051F
#define Red 0xF800
#define Magenta 0xF81F //紫色
#define Green 0x07E0
#define Cyan 0x7FFF //蓝绿色
#define Yellow 0xFFE0
#define Danlanse 0X9EDD //淡蓝色[天蓝色]
#define Huise 0xC618
#define Se1 0X051D  //浅蓝色
#define Se2 0X78EF  //茄紫色
#define Se3 0X8802  //深棕色
#define Se4 0XFBE4  //亮橙色
#define Se5 0X2589  //墨绿色
#define Se6 0X7497  //墨蓝色
#define Se7 0X3A39  //蓝色
#define Se8 0XA254  //淡紫色
#define Se9 0XC618  //灰白色
#define Se10 0XBBCA //棕色
#define Se11 0XFD79 //粉色
#define Se12 0XB723 //黄绿色
#define Se13 0X9EDD //天蓝色
#define Se14 0X001F //亮蓝色
#define Se15 0X07E0 //亮绿色

#define HyalineBackColor 0x0001 // Lihao 透明背景

#define Line0 0
#define Line1 24
#define Line2 48
#define Line3 72
#define Line4 96
#define Line5 120
#define Line6 144
#define Line7 168
#define Line8 192
#define Line9 216

#define Horizontal 0x00
#define Vertical 0x01

void LCD_DB_AS_InPut(void);
void LCD_DB_AS_OutPut(void);
void LCD_WriteRAM(u16 RGB_Code);
void LCD_WriteRAM_Prepare(void);

void LCD_Initializtion(void);
void Lcd_SetCursor(u8 x, u16 y);
void Lcd_SetWindows(u8 StartX, u16 StartY, u8 EndX, u16 EndY);
void Lcd_Clear(u16 Color);
void LCD_Write(uint16_t PortVal);
uint16_t LCD_Read();
void Draw_Line___(u8 x, u8 y, u8 Len, u16 point, u8 Dir);
void Draw_Bar(int xPos, int yPos, int Length, int width, int BkPoint, int ISBK);
void Swap_Int(int *a, int *b);
void Draw_Line(int x1, int y1, int x2, int y2, u16 Color);
void _Draw_Circle_8(int xc, int yc, int x, int y, u16 Color);
void Draw_Circle(int xc, int yc, int r, int fill, u16 Color);
void Draw_AngelLine(u16 x0, u16 y0, u16 angel, u16 length1, u16 color);
#endif
